/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import com.sun.org.apache.xpath.internal.XPathContext;
import com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl;
import index.Element;
import index.ElementHandler;
import index.StatsWordElement;
import index.Word;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author Lu
 */
public class TestElementHandler {

    public static void main(String[] args) throws XPathExpressionException {
        SAXParserFactory fabrique = SAXParserFactory.newInstance();
        SAXParser parseur;
        try {
            parseur = fabrique.newSAXParser();
            File fichier = new File("..\\Collection\\d001.xml");
            DefaultHandler gestionnaire = new ElementHandler();
            ((ElementHandler) gestionnaire).initNewFile(fichier);

            parseur.parse(fichier, gestionnaire);

            for(Element e : ((ElementHandler) gestionnaire).getElementList()){
                System.out.println(e.getXPath());
            }
            for (ArrayList<StatsWordElement> l : ((ElementHandler) gestionnaire).getStats()) {
                for (StatsWordElement w : l) {
                    System.out.println(w);
                }
            }

             for(Word w : ((ElementHandler) gestionnaire).getWordIndex()){
                System.out.println(w.getName());
            }


        } catch (ParserConfigurationException ex) {
            Logger.getLogger(TestElementHandler.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SAXException ex) {
            Logger.getLogger(TestElementHandler.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(TestElementHandler.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
